home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Text-Viewer / MSWordView / mswordview_src / blip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-06  |  25.9 KB  |  930 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include "config.h"
  6. #include "mswordview.h"
  7.  
  8. extern FILE *outputfile;
  9. extern FILE *erroroutput;
  10. extern char *outputfilename;
  11. extern char *imagesdir;
  12.  
  13. extern int madeinmac;
  14.  
  15. char failsafe[1];
  16.  
  17. extern int errno;
  18.  
  19. U16 idlist[NOOFIDS] = {0,0x216,0x3D4,0x542,0x6E0,0x46A,0x7A8,0x800};
  20.  
  21.  
  22. long get_picture_header(U32 fcPic,FILE *data, U32 *len, U16 *datatype)
  23.     {
  24.     U8 i,j;
  25.     error(erroroutput,"seeking to %x\n",fcPic);
  26.     fseek(data,fcPic,SEEK_SET);
  27.     *len = read_32ubit(data);
  28.     error(erroroutput,"the no of bytes in this PIC is %d\n",*len);
  29.     i = getc(data);
  30.     error(erroroutput,"the no of bytes of the PIC is %x\n",i);
  31.     *datatype = read_16ubit(data);
  32.     error(erroroutput,"an mm is %x\n",*datatype);
  33.     error(erroroutput,"an mm is %x\n",read_16ubit(data));
  34.     error(erroroutput,"an mm is %x\n",read_16ubit(data));
  35.     error(erroroutput,"an mm is %x\n",read_16ubit(data));
  36.     for (j=0;j<(i-13);j++)
  37.         getc(data);
  38.     *len = *len - i;
  39.     return(ftell(data));
  40.     }
  41.  
  42.  
  43. obj_by_spid * get_blips(U32 fcDggInfo,U32 lcbDggInfo,FILE *tablefd,FILE *mainfd,int *noofblips,int streamtype,obj_by_spid **realhead)
  44.     {
  45.     U16 element;
  46.     U32 len;
  47.     U32 fulllen=0;
  48.     U32 full02len=0;
  49.     U32 full00len=0;
  50.     long pos02;
  51.     long pos00;
  52.     U32 templen1;
  53.     U32 templen2;
  54.     U32 noofpics;
  55.     U32 offset;
  56.     int i;
  57.     FILE *graphic;
  58.     char *buffer=NULL;
  59.     obj_by_spid *head=NULL;
  60.     obj_by_spid *p=NULL;
  61.     char *imageprefix=NULL;
  62.  
  63.     int currentspid=0;
  64.     
  65.     U16 spids[1024];
  66.     char **names;
  67.     int *no;
  68.     char *names01[1024];
  69.     static char *names08[1024];
  70.     static int no01=0;
  71.     static int no08=0;
  72.     int decompressf=0;
  73.     U32 inlen=0;
  74.     U32 outlen=0;
  75.  
  76.     U16 id;
  77.     U32 op;
  78.     U16 msofbh;
  79.     U16 extra=0;
  80.     U32 flags;
  81.  
  82.     *noofblips=0;
  83.  
  84.     if (imagesdir == NULL)
  85.         {
  86.         imageprefix = malloc(strlen(outputfilename)+1);
  87.         if (imageprefix == NULL)
  88.             {
  89.             fprintf(erroroutput,"arrgh, no mem\n");
  90.             exit(-1);
  91.             }
  92.         strcpy(imageprefix,outputfilename);
  93.         }
  94.     else
  95.         {
  96.         imageprefix = malloc(strlen(imagesdir)+2+strlen(ms_basename(outputfilename)));
  97.         if (imageprefix == NULL)
  98.             {
  99.             fprintf(erroroutput,"arrgh, no mem\n");
  100.             exit(-1);
  101.             }
  102.         sprintf(imageprefix,"%s/%s",imagesdir,ms_basename(outputfilename));
  103.         }
  104.  
  105.  
  106.     if (streamtype == 0x01)
  107.         {
  108.         mainfd=tablefd;
  109.         names=names01;
  110.         no = &no01;
  111.         memset(names, 0, 1024);
  112.         }
  113.     else        
  114.         {
  115.         names=names08;
  116.         no = &no08;
  117.         }
  118.  
  119.     if ( (*no) == 0)    
  120.         memset(names, 0, 1024);
  121.  
  122.     if ((realhead != NULL) && (*realhead != NULL))
  123.         {
  124.         error(erroroutput,"adding onto an existing list\n");
  125.         p=*realhead;
  126.         head=*realhead;
  127.         error(erroroutput,"REAL TEST, filename is %s\n",(*realhead)->filename);
  128.         error(erroroutput,"head isnt null here\n");
  129.  
  130.         error(erroroutput,"TEST, no is %d, filename is %s\n",*no,p->filename);
  131.  
  132.         while (p->next != NULL)
  133.             p = p->next;
  134.         }
  135.  
  136.     fseek(tablefd,fcDggInfo,SEEK_SET);
  137.  
  138.     while(fulllen < lcbDggInfo)
  139.         {
  140.         error(erroroutput,"at this moment fullen is %d, lcbDggInfo is %d, pos is %x, streamtype is %d\n",fulllen,lcbDggInfo,ftell(tablefd),streamtype);
  141.         msofbh = read_16ubit(tablefd);
  142.         element = read_16ubit(tablefd);
  143.         len = read_32ubit(tablefd);
  144.  
  145.         fulllen+=8;
  146.         error(erroroutput,"len is %x, element is %x\n",len,element);
  147.         error(erroroutput,"dec, fullen is %d, lcbDggInfo is %d\n",fulllen,lcbDggInfo);
  148.         switch (element)
  149.             {
  150.             case 0xf000:
  151.                 error(erroroutput,"f000 here\n");
  152.                 pos00 = ftell(tablefd);
  153.                 full00len=0;
  154.                 templen2 = len;
  155.                 while (full00len < templen2)
  156.                     {
  157.                     error(erroroutput,"at this moment full00en is %d, templen is %d\n",full00len,templen2);
  158.                     msofbh = read_16ubit(tablefd);
  159.                     element = read_16ubit(tablefd);
  160.                     len = read_32ubit(tablefd);
  161.                     full00len+=8;
  162.                     error(erroroutput,"len is %x, element is %x\n",len,element);
  163.                     error(erroroutput,"dec, fullen is %d, lcbDggInfo is %d\n",full00len,lcbDggInfo);
  164.                     switch (element)
  165.                         {
  166.                         case 0xf006:
  167.                             error(erroroutput,"1-->%d\n",read_32ubit(tablefd));
  168.                             error(erroroutput,"2-->%d\n",read_32ubit(tablefd));
  169.                             error(erroroutput,"3-->%d\n",read_32ubit(tablefd));
  170.                             noofpics = read_32ubit(tablefd);
  171.                             full00len+=16;
  172.                             error(erroroutput,"there are %d pics visible\n",noofpics);
  173.                             /*
  174.                             for (i=0;i<noofpics;i++)
  175.                                 {
  176.                                 read_32ubit(tablefd);
  177.                                 read_32ubit(tablefd);
  178.                                 full00len+=8;
  179.                                 }
  180.                             */
  181.                             for (i=16;i<len;i++)
  182.                                 {
  183.                                 getc(tablefd);
  184.                                 full00len++;
  185.                                 }
  186.                             break;
  187.                         case 0xf00b:
  188.                             id = read_16ubit(tablefd);
  189.                             op = read_32ubit(tablefd);
  190.                             error(erroroutput,"id is %x\n",id);
  191.                             error(erroroutput,"op is %x\n",op);
  192.                             full00len+=6;
  193.  
  194.                             if ((id & 0x4000) && (!(id & 0x8000)))
  195.                                 {
  196.                                 error(erroroutput,"talking about blit id of %x,mine %x\n",op,id&0x3fff);
  197.                                 p->filename=names[op-1];
  198.                                 if (p->filename==NULL)
  199.                                     {
  200.                                     /*
  201.                                     this means that there was no blip in the blip store to match with this,
  202.                                     from looking at it it looks like this means that there will be data in
  203.                                     the client data to fill this blank
  204.                                     so im going to temporarily allow a temp in the filename when we come
  205.                                     to blips to be assigned
  206.                                     */
  207.                                     }
  208.                                 }
  209.  
  210.                             if (p==NULL)
  211.                                 error(erroroutput,"SO p is NULL\n");
  212.                             else if (p->filename == NULL)
  213.                                 error(erroroutput,"SO p->filenamae is NULL\n");
  214.                             else
  215.                                 error(erroroutput,"SO spid %x has a filename of %s\n",p->spid,p->filename);
  216.  
  217.                             for(i=0;i<len-6;i++)
  218.                                 {
  219.                                 getc(tablefd);
  220.                                 full00len++;
  221.                                 }
  222.                             break;
  223.                         case 0xf001: /*container for pics*/
  224.                             break;
  225.                         case 0xf007: /*a pic, yeah!!*/
  226.                             error(erroroutput,"window pic type is %d\n",getc(tablefd));    
  227.                             error(erroroutput,"mac pic type is %d\n",getc(tablefd));    
  228.                             full00len+=2;
  229.                             for(i=0;i<18;i++)
  230.                                 getc(tablefd);
  231.                             full00len+=18;
  232.                             error(erroroutput,"pic data len is (%x)\n",read_32ubit(tablefd));
  233.                             error(erroroutput,"blid no is %d\n",read_32ubit(tablefd));
  234.                             offset = read_32ubit(tablefd);
  235.                             full00len+=12;
  236.                             error(erroroutput,"file offset into main stream is %x\n",offset);
  237.  
  238.                             read_32ubit(tablefd);
  239.                             full00len+=4;
  240.  
  241.                             buffer = malloc(strlen("-graphic100-mswv.tiff")+80+strlen(imageprefix));
  242.                             if (buffer==NULL)
  243.                                 {
  244.                                 fprintf(erroroutput,"no mem\n");
  245.                                 exit(-1);
  246.                                 }
  247.  
  248.                             error(erroroutput,"were at %x\n",ftell(tablefd));
  249.                             if ((offset != 0xffffffffUL) || (streamtype == 0x01))
  250.                                 {
  251.                                 if (streamtype == 0x08)
  252.                                     fseek(mainfd,offset,SEEK_SET);
  253.                                 error(erroroutput,"were at %x\n",ftell(mainfd));
  254.                                 msofbh = read_16ubit(mainfd);
  255.                                 error(erroroutput,"msofbh is %x, inst is %x\n",msofbh ,msofbh>> 4);
  256.                                 msofbh = msofbh >> 4;
  257.                                 extra=0;
  258.                                 for (i=0;i<NOOFIDS;i++)
  259.                                     {
  260.                                     if ((msofbh ^ idlist[i]) == 1)
  261.                                         {
  262.                                         error(erroroutput,"extra 16\n");
  263.                                         extra=16;
  264.                                         }
  265.                                     }
  266.                                 element = read_16ubit(mainfd);
  267.                                 error(erroroutput,"element is %x\n",element);
  268.                                 len = read_32ubit(mainfd);
  269.                                 if (streamtype == 0x01)
  270.                                     full00len+=8;
  271.                                 error(erroroutput,"graphic len is %x, pos is %x\n",len,ftell(mainfd));
  272.  
  273.                                 if ((element >= 0xf018) && (element <= 0xf117))
  274.                                     {
  275.                                     switch (element - 0xf018)
  276.                                         {
  277.                                         case 6:
  278.                                             sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"png");
  279.                                             for(i=0;i<(17+extra);i++)
  280.                                                 getc(mainfd);
  281.                                             len-=(17+extra);
  282.                                             if (streamtype == 0x01)
  283.                                                 full00len+=(17+extra);
  284.                                             break;
  285.                                         case 5:
  286.                                             sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"jpg");
  287.                                             error(erroroutput,"extra is %d\n",extra);
  288.                                             for(i=0;i<(17+extra);i++)
  289.                                                 getc(mainfd);
  290.                                             len-=(17+extra);
  291.                                             if (streamtype == 0x01)
  292.                                                 full00len+=(17+extra);
  293.                                             error(erroroutput,"jpg the current pos of the beast is %x\n",ftell(mainfd));
  294.                                             break;
  295.                                         case 4:
  296.                                             sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"pict");
  297.                                             for(i=0;i<(17+extra);i++)
  298.                                                 getc(mainfd);
  299.                                             len-=(17+extra);
  300.                                             if (streamtype == 0x01)
  301.                                                 full00len+=(17+extra);
  302.                                             break;
  303.                                         case 3:
  304.                                             decompressf = setdecom();
  305.                                             if (decompressf)
  306.                                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"wmf");
  307.                                             else
  308.                                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"wmf.lz");
  309.                                             for(i=0;i<(16+extra);i++)
  310.                                                 getc(mainfd);
  311.                                             outlen = read_32ubit(mainfd);
  312.                                             error(erroroutput,"uncompressed size would be %d\n",outlen);
  313.                                             for(i=0;i<24;i++)
  314.                                                 getc(mainfd);
  315.                                             inlen = read_32ubit(mainfd);
  316.                                             error(erroroutput,"compressed size is %d\n",inlen);
  317.                                             error(erroroutput,"compression is %d\n",getc(mainfd));
  318.                                             error(erroroutput,"filter is %d\n",getc(mainfd));
  319.                                             len-=(50+extra);
  320.                                             if (streamtype == 0x01)
  321.                                                 full00len+=(50+extra);
  322.                                             break;
  323.                                         case 2:
  324.                                             decompressf = setdecom();
  325.                                             if (decompressf)
  326.                                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"emf");
  327.                                             else
  328.                                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"emf.lz");
  329.                                             for(i=0;i<(16+extra);i++)
  330.                                                 getc(mainfd);
  331.                                             outlen = read_32ubit(mainfd);
  332.                                             error(erroroutput,"uncompressed size would be %d\n",outlen);
  333.                                             for(i=0;i<24;i++)
  334.                                                 getc(mainfd);
  335.                                             inlen = read_32ubit(mainfd);
  336.                                             error(erroroutput,"compressed size is %d\n",inlen);
  337.                                             error(erroroutput,"compression is %d\n",getc(mainfd));
  338.                                             error(erroroutput,"filter is %d\n",getc(mainfd));
  339.                                             len-=(50+extra);
  340.                                             if (streamtype == 0x01)
  341.                                                 full00len+=(50+extra);
  342.                                             break;
  343.                                         case 7:
  344.                                             sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"dib");
  345.                                             for(i=0;i<(17+extra);i++)
  346.                                                 getc(mainfd);
  347.                                             len-=(17+extra);
  348.                                             if (streamtype == 0x01)
  349.                                                 full00len+=(17+extra);
  350.                                             break;
  351.                                         default:
  352.                                             sprintf(buffer,"%s-graphic-dontknow%d-mswv-%d.jpg",imageprefix,(*no)+1,streamtype);
  353.                                             len=0;
  354.                                             break;
  355.                                         }
  356.  
  357.  
  358.                                     error(erroroutput,"this the current pos of the beast is %x\n",ftell(mainfd));
  359.  
  360.                                     if (decompressf)
  361.                                         /*
  362.                                         graphic = tmpfile();
  363.                                         */
  364.                                         graphic = fopen("/tmp/test.wmf.lzzed","w+b");
  365.                                     else
  366.                                         graphic = fopen(buffer,"wb");
  367.  
  368.                                     if (graphic == NULL)
  369.                                         {
  370.                                         fprintf(erroroutput,"warning couldnt create file %s, ignoring \n(failure was :%s)\n",buffer,strerror(errno));
  371.                                         for (i=0;i<len;i++)
  372.                                             {
  373.                                             getc(mainfd);
  374.                                             if (streamtype == 0x01)
  375.                                                 full00len++;
  376.                                             }
  377.                                         }
  378.                                     else
  379.                                         {
  380.                                         error(erroroutput,"len changed to %d\n",len);
  381.                                         for (i=0;i<len;i++)
  382.                                             {
  383.                                             putc(getc(mainfd),graphic);
  384.                                             if (streamtype == 0x01)
  385.                                                 full00len++;
  386.                                             }
  387.                                         if (decompressf)
  388.                                             {
  389.                                             fflush(graphic);
  390.                                             rewind(graphic);
  391.                                             decompress(graphic,buffer,inlen,outlen);
  392.                                             decompressf=0;
  393.                                             }
  394.                                             
  395.                                         fclose(graphic);
  396.                                         }
  397.                                     }
  398.  
  399.                                 if (buffer!=NULL)
  400.                                     names[(*no)++] = buffer;
  401.                                 else
  402.                                     (*no)++;
  403.  
  404.                                 error(erroroutput,"name is %s, index %d\n",names[(*no)-1],(*no)-1);
  405.  
  406.                                 error(erroroutput,"blit no %d is filename %s\n",*no,names[(*no)-1]);
  407.  
  408.  
  409.                                 if (p != NULL)
  410.                                     if (p->filename == NULL)
  411.                                         p->filename = buffer;
  412.                                 
  413.                                 error(erroroutput,"THE FILENAME is %s\n",buffer);
  414.                                 }
  415.                             else
  416.                                 {
  417.                                 error(erroroutput,"would have been %s-graphic-badoffset%d-mswv.jpg",imageprefix,(*no)+1);
  418.                                 error(erroroutput,"THE FILENAME is %s\n",buffer);
  419.                                 free(buffer);
  420.                                 }
  421.                             error(erroroutput,"location is %x\n",ftell(tablefd));
  422.                             break;
  423.                         default:
  424.                             error(erroroutput,"unrecognized element %x len is %d\n",element,len);
  425.                             error(erroroutput,"were here at %x\n",ftell(tablefd));
  426.                             for(i=0;i<len;i++)
  427.                                 {
  428.                                 getc(tablefd);
  429.                                 full00len++;
  430.                                 }
  431.                             break;
  432.                         }
  433.                     }
  434.                 templen2++;
  435.                 fulllen+=templen2;
  436.                 pos00 = pos00+=templen2;
  437.                 error(erroroutput,"the position to seek to is fulllen is %d,%x\n",fulllen,pos00);
  438.                 fseek(tablefd,pos00,SEEK_SET);
  439.                 break;
  440.             case 0xf002: /*container for page or something*/
  441.                 error(erroroutput,"f002 here\n");
  442.                 pos02 = ftell(tablefd);
  443.                 full02len=0;
  444.                 templen1 = len;
  445.                 while (full02len < templen1)
  446.                     {
  447.                     error(erroroutput,"at this moment full02en is %d, templen is %d\n",full02len,templen1);
  448.                     msofbh = read_16ubit(tablefd);
  449.                     element = read_16ubit(tablefd);
  450.                     len = read_32ubit(tablefd);
  451.                     full02len+=8;
  452.                     error(erroroutput,"len is %x, element is %x\n",len,element);
  453.                     error(erroroutput,"dec, fullen is %d, lcbDggInfo is %d\n",full02len,lcbDggInfo);
  454.                     switch (element)
  455.                         {
  456.                         case 0xf008: /*msofbtDg*/
  457.                             read_32ubit(tablefd);
  458.                             read_32ubit(tablefd);
  459.                             full02len+=8;
  460.                             break;
  461.                         case 0xf003: /*container for many shapes*/
  462.                             break;
  463.                         case 0xf004: /*container for a shape*/
  464.                             break;
  465.                         case 0xf00a:
  466.                             spids[currentspid++] = read_32ubit(tablefd);
  467.                             error(erroroutput,"The ID of this ENTITY is %x\n",spids[currentspid-1]);
  468.                             /*
  469.                             this is the identity of the object, the real spid as far 
  470.                             as im concerned, following this will be the shape property
  471.                             table that will have a list of blits associated with
  472.                             this id, (referred to by an index into the previous blit 
  473.                             table)
  474.                             */
  475.                             flags = read_32ubit(tablefd);
  476.                             error(erroroutput,"flags is %x\n",flags);
  477.  
  478.                             if (head == NULL)
  479.                                 {
  480.                                 head = (obj_by_spid*) malloc(sizeof(obj_by_spid));
  481.                                 error(erroroutput,"head is null\n");
  482.                                 if (head == NULL)
  483.                                     {
  484.                                     error(erroroutput,"no mem\n");
  485.                                     exit(-1);
  486.                                     }
  487.                                 p = head;
  488.                                 }
  489.                             else
  490.                                 {
  491.                                 p->next = (obj_by_spid*) malloc(sizeof(obj_by_spid));
  492.                                 error(erroroutput,"head is not null\n");
  493.                                 if (p->next == NULL)
  494.                                     {
  495.                                     error(erroroutput,"no mem\n");
  496.                                     exit(-1);
  497.                                     }
  498.                                 p = p->next;
  499.                                 }
  500.                             
  501.                             p->spid = spids[currentspid-1];
  502.                             /*
  503.                             p->filename = failsafe;
  504.                             */
  505.                             p->filename = NULL;
  506.                             p->next = NULL;
  507.                             (*noofblips)++;
  508.                             
  509.                             full02len+=8;
  510.                             for(i=0;i<len-8;i++)
  511.                                 {
  512.                                 getc(tablefd);
  513.                                 full02len++;
  514.                                 }
  515.                             break;
  516.                         case 0xf00b:
  517.                             id = read_16ubit(tablefd);
  518.                             op = read_32ubit(tablefd);
  519.                             error(erroroutput,"id is %x\n",id);
  520.                             error(erroroutput,"op is %x\n",op);
  521.  
  522.                             if ((id & 0x4000) && (!(id & 0x8000)))
  523.                                 {
  524.                                 error(erroroutput,"talking about blit id of %x,mine %x\n",op,id&0x3fff);
  525.                                 p->filename=names[op-1];
  526.                                 if (p->filename==NULL)
  527.                                     {
  528.                                     /*
  529.                                     this means that there was no blip in the blip store to match with this,
  530.                                     from looking at it it looks like this means that there will be data in
  531.                                     the client data to fill this blank
  532.                                     so im going to temporarily allow a temp in the filename when we come
  533.                                     to blips to be assigned
  534.                                     */
  535.                                     }
  536.                                 }
  537.  
  538.                             if (p==NULL)
  539.                                 error(erroroutput,"SO p is NULL\n");
  540.                             else if (p->filename == NULL)
  541.                                 error(erroroutput,"SO p->filenamae is NULL\n");
  542.                             else
  543.                                 error(erroroutput,"SO spid %x has a filename of %s\n",p->spid,p->filename);
  544.  
  545.                             full02len+=6;
  546.                             for(i=0;i<len-6;i++)
  547.                                 {
  548.                                 getc(tablefd);
  549.                                 full02len++;
  550.                                 }
  551.                             break;
  552.                         default:
  553.                             error(erroroutput,"unrecognized element %x len is %d\n",element,len);
  554.                             error(erroroutput,"were here at %x\n",ftell(tablefd));
  555.                             for(i=0;i<len;i++)
  556.                                 {
  557.                                 getc(tablefd);
  558.                                 full02len++;
  559.                                 }
  560.                             break;
  561.                         }
  562.                     }
  563.                 templen1++;
  564.                 fulllen+=templen1;
  565.                 pos02 = pos02+=templen1;
  566.                 error(erroroutput,"the position to seek to is fulllen %d,%x\n",fulllen,pos02);
  567.                 fseek(tablefd,pos02,SEEK_SET);
  568.                 break;
  569.             case 0xf005: /*container for shape rules*/
  570.                 break;
  571.             case 0xf004: /*container for a shape*/
  572.                 break;
  573.             case 0xf007: /*a pic, yeah!!*/
  574.                 error(erroroutput,"window pic type is %d\n",getc(tablefd));    
  575.                 error(erroroutput,"mac pic type is %d\n",getc(tablefd));    
  576.                 fulllen+=2;
  577.                 for(i=0;i<18;i++)
  578.                     getc(tablefd);
  579.                 fulllen+=18;
  580.                 error(erroroutput,"pic data len is (%x)\n",read_32ubit(tablefd));
  581.                 error(erroroutput,"blid no is %d\n",read_32ubit(tablefd));
  582.                 offset = read_32ubit(tablefd);
  583.                 fulllen+=12;
  584.                 error(erroroutput,"file offset into main stream is %x\n",offset);
  585.  
  586.                 read_32ubit(tablefd);
  587.                 fulllen+=4;
  588.  
  589.                 buffer = malloc(strlen("-graphic100-mswv.tiff")+80+strlen(imageprefix));
  590.                 if (buffer==NULL)
  591.                     {
  592.                     fprintf(erroroutput,"no mem\n");
  593.                     exit(-1);
  594.                     }
  595.  
  596.                 error(erroroutput,"were at %x\n",ftell(tablefd));
  597.                 if ((offset != 0xffffffffUL) || (streamtype == 0x01))
  598.                     {
  599.                     if (streamtype == 0x08)
  600.                         fseek(mainfd,offset,SEEK_SET);
  601.                     error(erroroutput,"were at %x\n",ftell(mainfd));
  602.                     msofbh = read_16ubit(mainfd);
  603.                     error(erroroutput,"element is %x, inst is %x\n",msofbh ,msofbh>> 4);
  604.                     msofbh = msofbh >> 4;
  605.                     extra=0;
  606.                     for (i=0;i<NOOFIDS;i++)
  607.                         {
  608.                         if ((msofbh ^ idlist[i]) == 1)
  609.                             {
  610.                             error(erroroutput,"extra 16\n");
  611.                             extra=16;
  612.                             }
  613.                         }
  614.                     element = read_16ubit(mainfd);
  615.                     len = read_32ubit(mainfd);
  616.                     if (streamtype == 0x01)
  617.                         fulllen+=8;
  618.                     error(erroroutput,"graphic len is %x, element is %x\n",len,element);
  619.  
  620.                     if ((element >= 0xf018) && (element <= 0xf117))
  621.                         {
  622.                         switch (element - 0xf018)
  623.                             {
  624.                             case 6:
  625.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"png");
  626.                                 for(i=0;i<(17+extra);i++)
  627.                                     getc(mainfd);
  628.                                 len-=(17+extra);
  629.                                 if (streamtype == 0x01)
  630.                                     fulllen+=(17+extra);
  631.                                 break;
  632.                             case 5:
  633.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"jpg");
  634.                                 for(i=0;i<(17+extra);i++)
  635.                                     getc(mainfd);
  636.                                 len-=(17+extra);
  637.                                 if (streamtype == 0x01)
  638.                                     fulllen+=(17+extra);
  639.                                 break;
  640.                             case 4:
  641.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"pict");
  642.                                 for(i=0;i<(17+extra);i++)
  643.                                     getc(mainfd);
  644.                                 len-=(17+extra);
  645.                                 if (streamtype == 0x01)
  646.                                     fulllen+=(17+extra);
  647.                                 break;
  648.                             case 3:
  649.                                 decompressf = setdecom();
  650.                                 if (decompressf)
  651.                                     sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"wmf");
  652.                                 else
  653.                                     sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"wmf.lz");
  654.                                 for(i=0;i<(16+extra);i++)
  655.                                     getc(mainfd);
  656.                                 outlen = read_32ubit(mainfd);
  657.                                 error(erroroutput,"uncompressed size would be %d\n",outlen);
  658.                                 for(i=0;i<24;i++)
  659.                                     getc(mainfd);
  660.                                 inlen = read_32ubit(mainfd);
  661.                                 error(erroroutput,"compressed size is %d\n",inlen);
  662.                                 error(erroroutput,"compression is %d\n",getc(mainfd));
  663.                                 error(erroroutput,"filter is %d\n",getc(mainfd));
  664.                                 len-=(50+extra);
  665.                                 if (streamtype == 0x01)
  666.                                     fulllen+=(50+extra);
  667.                                 break;
  668.                             case 2:
  669.                                 decompressf = setdecom();
  670.                                 if (decompressf)
  671.                                     sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"emf");
  672.                                 else
  673.                                     sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"emf.lz");
  674.                                 for(i=0;i<(16+extra);i++)
  675.                                     getc(mainfd);
  676.                                 outlen = read_32ubit(mainfd);
  677.                                 error(erroroutput,"uncompressed size would be %d\n",outlen);
  678.                                 for(i=0;i<24;i++)
  679.                                     getc(mainfd);
  680.                                 inlen = read_32ubit(mainfd);
  681.                                 error(erroroutput,"compressed size is %d\n",inlen);
  682.                                 error(erroroutput,"compression is %d\n",getc(mainfd));
  683.                                 error(erroroutput,"filter is %d\n",getc(mainfd));
  684.                                 len-=(50+extra);
  685.                                 if (streamtype == 0x01)
  686.                                     fulllen+=(50+extra);
  687.                                 break;
  688.                             case 7:
  689.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"dib");
  690.                                 for(i=0;i<(17+extra);i++)
  691.                                     getc(mainfd);
  692.                                 len-=(17+extra);
  693.                                 if (streamtype == 0x01)
  694.                                     fulllen+=(17+extra);
  695.                                 break;
  696.                             default:
  697.                                 sprintf(buffer,"%s-graphic-dontknow%d-mswv-%d.jpg",imageprefix,(*no)+1,streamtype);
  698.                                 len=0;
  699.                                 break;
  700.                             }
  701.  
  702.                         error(erroroutput,"the current pos of the beast is %x\n",ftell(mainfd));
  703.                         if (decompressf)
  704.                         /*
  705.                             graphic = tmpfile();
  706.                         */
  707.                             graphic = fopen("/tmp/test.wmf2.lzzed","w+b");
  708.                         else
  709.                             graphic = fopen(buffer,"wb");
  710.                         if (graphic == NULL)
  711.                             {
  712.                             fprintf(erroroutput,"warning couldnt create file %s, ignoring \n(failure was :%s)\n",buffer,strerror(errno));
  713.                             for (i=0;i<len;i++)
  714.                                 {
  715.                                 getc(mainfd);
  716.                                 if (streamtype == 0x01)
  717.                                     fulllen++;
  718.                                 }
  719.                             }
  720.                         else
  721.                             {
  722.                             error(erroroutput,"len changed to %d\n",len);
  723.                             for (i=0;i<len;i++)
  724.                                 {
  725.                                 putc(getc(mainfd),graphic);
  726.                                 if (streamtype == 0x01)
  727.                                     fulllen++;
  728.                                 }
  729.                             if (decompressf)
  730.                                 {
  731.                                 fflush(graphic);
  732.                                 rewind(graphic);
  733.                                 decompress(graphic,buffer,inlen,outlen);
  734.                                 decompressf=0;
  735.                                 }
  736.                                 
  737.                             fclose(graphic);
  738.                             }
  739.                         }
  740.  
  741.                     if (buffer!=NULL)
  742.                         names[(*no)++] = buffer;
  743.                     else
  744.                         (*no)++;
  745.  
  746.                     error(erroroutput,"name is %s, index %d\n",names[(*no)-1],(*no)-1);
  747.  
  748.                     error(erroroutput,"blit no %d is filename %s\n",*no,names[(*no)-1]);
  749.  
  750.  
  751.                     if (p != NULL)
  752.                         if (p->filename == NULL)
  753.                             p->filename = buffer;
  754.                     
  755.                     error(erroroutput,"THE FILENAME is %s\n",buffer);
  756.                     }
  757.                 else
  758.                     {
  759.                     error(erroroutput,"would have been %s-graphic-badoffset%d-mswv.jpg",imageprefix,(*no)+1);
  760.                     error(erroroutput,"THE FILENAME is %s\n",buffer);
  761.                     free(buffer);
  762.                     }
  763.                 error(erroroutput,"location is %x\n",ftell(tablefd));
  764.                 break;
  765.             case 0xf00a:
  766. #if 0
  767.                 error(erroroutput,"The ID of this ENTITY is %x\n",read_32ubit(tablefd));
  768.                 flags = read_32ubit(tablefd);
  769.                 error(erroroutput,"flags is %x\n",flags);
  770.                 fulllen+=8;
  771.                 for(i=0;i<len-8;i++)
  772.                     {
  773.                     getc(tablefd);
  774.                     fulllen++;
  775.                     }
  776. #endif                            
  777.                 spids[currentspid++] = read_32ubit(tablefd);
  778.                 error(erroroutput,"The ID of this ENTITY is %x\n",spids[currentspid-1]);
  779.                 /*
  780.                 this is the identity of the object, the real spid as far 
  781.                 as im concerned, following this will be the shape property
  782.                 table that will have a list of blits associated with
  783.                 this id, (referred to by an index into the previous blit 
  784.                 table)
  785.                 */
  786.                 flags = read_32ubit(tablefd);
  787.                 error(erroroutput,"flags is %x\n",flags);
  788.  
  789.                 if (head == NULL)
  790.                     {
  791.                     head = (obj_by_spid*) malloc(sizeof(obj_by_spid));
  792.                     error(erroroutput,"head is null\n");
  793.                     if (head == NULL)
  794.                         {
  795.                         error(erroroutput,"no mem\n");
  796.                         exit(-1);
  797.                         }
  798.                     p = head;
  799.                     }
  800.                 else
  801.                     {
  802.                     p->next = (obj_by_spid*) malloc(sizeof(obj_by_spid));
  803.                     error(erroroutput,"head is not null\n");
  804.                     if (p->next == NULL)
  805.                         {
  806.                         error(erroroutput,"no mem\n");
  807.                         exit(-1);
  808.                         }
  809.                     p = p->next;
  810.                     }
  811.                 
  812.                 p->spid = spids[currentspid-1];
  813.                 /*
  814.                 p->filename = failsafe;
  815.                 */
  816.                 p->filename = NULL;
  817.                 p->next = NULL;
  818.                 (*noofblips)++;
  819.                 
  820.                 fulllen+=8;
  821.                 for(i=0;i<len-8;i++)
  822.                     {
  823.                     getc(tablefd);
  824.                     fulllen++;
  825.                     }
  826.                 break;
  827.             case 0xf00b:
  828.                 id = read_16ubit(tablefd);
  829.                 op = read_32ubit(tablefd);
  830.                 error(erroroutput,"id is %x\n",id);
  831.                 error(erroroutput,"op is %x\n",op);
  832.  
  833.                 if ((id & 0x4000) && (!(id & 0x8000)))
  834.                     {
  835.                     error(erroroutput,"talking about blit id of %x,mine %x\n",op,id&0x3fff);
  836.                     p->filename=names[op-1];
  837.                     if (p->filename==NULL)
  838.                         {
  839.                         /*
  840.                         this means that there was no blip in the blip store to match with this,
  841.                         from looking at it it looks like this means that there will be data in
  842.                         the client data to fill this blank
  843.                         so im going to temporarily allow a temp in the filename when we come
  844.                         to blips to be assigned
  845.                         */
  846.                         }
  847.                     }
  848.  
  849.                 if (p==NULL)
  850.                     error(erroroutput,"SO p is NULL\n");
  851.                 else if (p->filename == NULL)
  852.                     error(erroroutput,"SO p->filenamae is NULL\n");
  853.                 else
  854.                     error(erroroutput,"SO spid %x has a filename of %s\n",p->spid,p->filename);
  855.  
  856.                 fulllen+=6;
  857.                 for(i=0;i<len-6;i++)
  858.                     {
  859.                     getc(tablefd);
  860.                     fulllen++;
  861.                     }
  862.                 break;
  863. #if 0                
  864.             case 0xf11e:
  865.                 /*i dont quite understand this for now*/
  866.                 len=25;
  867.                 for(i=0;i<len;i++)
  868.                     {
  869.                     getc(tablefd);
  870.                     fulllen++;
  871.                     }
  872.                 break;
  873. #endif
  874.             default:
  875.                 error(erroroutput,"unrecognized element %x len is %d\n",element,len);
  876.                 error(erroroutput,"were here at %x\n",ftell(tablefd));
  877.                 for(i=0;i<len;i++)
  878.                     {
  879.                     getc(tablefd);
  880.                     fulllen++;
  881.                     }
  882.                 break;
  883.             }
  884.         }
  885.  
  886.     if (imageprefix != NULL)
  887.         free(imageprefix);
  888.     return(head);
  889.     }
  890.  
  891. void output_draw(U32 cp,textportions *portions)
  892.     {
  893.     int i;
  894.     U16 ourspid=0;
  895.     obj_by_spid *p;
  896.     
  897.     for (i=0;i<portions->noofficedraw;i++)
  898.         {
  899.         if (cp == portions->officedrawcps[i])
  900.             {
  901.             ourspid = portions->spids[i];
  902.             break;
  903.             }
  904.         }
  905.     
  906.     error(erroroutput,"outspid is %x in output_draw, only able to handle blips, not real draw objects as of yet\n",ourspid);
  907.  
  908.     error(erroroutput,"noofficedraw is %d portions->noofblipdata is %d\n",portions->noofficedraw,portions->noofblipdata);
  909.  
  910.     p = portions->ablipdata;
  911.  
  912.     if ((ourspid != 0) && (p != 0)) /*Craig J Copi <cjc5@po.cwru.edu>*/
  913.         {
  914.         /*search to see if theres a filename assiciated with this spid*/
  915.         for(i=0;i<portions->noofblipdata;i++)
  916.             {
  917.             error(erroroutput,"p->spid is %x\n",p->spid);
  918.             if (ourspid == p->spid)
  919.                 {
  920.                 outputimgsrc(p->filename);
  921.                 return;
  922.                 }
  923.             p = p->next;
  924.             }
  925.         }
  926.     error(erroroutput,"given spid %x, no luck\n",ourspid);
  927.     }
  928.  
  929.  
  930.